﻿using System.Linq;
using GalaSoft.MvvmLight;
using WinPhoneClient.Model;

namespace WinPhoneClient.ViewModel
{

    public class Page : ViewModelBase
    {
        public Page(string title)
        {
            Title = title;
        }

        public string Title { get; private set; }
    }

    public class Rect
    {
        public Rect(RectData rectData, double scale, int index)
        {
            X = rectData.Left/scale;
            Y = rectData.Top/scale;
            Width = rectData.Width/scale - 0.02;
            Height = rectData.Height/scale - 0.02;
            Number = index;
        }

        public double X { get; private set; }
        public double Y { get; private set; }
        public double Width { get; private set; }
        public double Height { get; private set; }
        public int Number { get; set; }
        public bool Free { get; set; }
    }

    public class RectData
    {
        public RectData() { }
        public RectData(double l, double t, double r, double b)
        {
            Left = l;
            Top = t;
            Right = r;
            Bottom = b;

        }
        public int Id;
        public double Left;
        public double Top;
        public double Right;
        public double Bottom;

        public double Width
        {
            get { return Right - Left; }
            set { Right = Left + value; }
        }

        public double Height
        {
            get { return Bottom - Top; }
            set { Bottom = Height + value; }
        }

    }

    public class MainViewModel : Page
    {
        public MainViewModel()
            : base("Map")
        {
            var data = new[]
                          {
                              new RectData(0, 185, 150, 245), //smaller
                              new RectData(0, 245, 150, 305), //smaller
                              new RectData(0, 305, 150, 370),
                              new RectData(0, 370, 150, 435),
                              new RectData(0, 435, 150, 500),
                              new RectData(0, 500, 150, 565),

                              new RectData(550, 130, 700, 195),
                              new RectData(550, 195, 700, 260),
                              new RectData(550, 260, 700, 325),
                              new RectData(550, 325, 700, 390),
                              new RectData(550, 390, 700, 455),
                              new RectData(550, 455, 700, 525),
                              new RectData(550, 525, 700, 580), //smaller
                              new RectData(550, 580, 700, 645),


                              new RectData(270, 130, 345, 270), new RectData(345, 130, 420, 270),
                              new RectData(270, 270, 345, 410), new RectData(345, 270, 420, 410),
                              new RectData(270, 410, 345, 550), new RectData(345, 410, 420, 550),
                              new RectData(270, 550, 345, 690), new RectData(345, 550, 420, 690)
                          };

            //double maxWidth = data.Max(r => r.Height);
            double maxWidth = 700;
            MapData = data.Select((r, i) => new Rect(r, maxWidth, i + 1)).ToArray();

        }

        public Rect[] MapData { get; private set; }
    }
}